blktap2: Fix another uninitialised value error
authorIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 10 May 2012 13:26:14 +0000 (14:26 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 10 May 2012 13:26:14 +0000 (14:26 +0100)
gcc  -O1 -fno-omit-frame-pointer -m32 -march=i686 -g -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wdeclaration-after-statement   -D__XEN_TOOLS__ -MMD -MF .block-remus.o.d -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -fno-optimize-sibling-calls -mno-tls-direct-seg-refs -Werror -g -Wno-unused -fno-strict-aliasing -I../include -I../drivers -I/home/osstest/build.12828.build-i386/xen-unstable/tools/blktap2/drivers/../../../tools/libxc -I/home/osstest/build.12828.build-i386/xen-unstable/tools/blktap2/drivers/../../../tools/include -D_GNU_SOURCE -DUSE_NFS_LOCKS  -c -o block-remus.o block-remus.c

block-remus.c: In function 'ramdisk_flush':
block-remus.c:508: error: 'buf' may be used uninitialized in this function
make[5]: *** [block-remus.o] Error 1

This is because gcc can see that merge_requests doesn't always set
*mergedbuf but gcc isn't able to prove that it always does so if
merge_requests returns 0 and that in that case the value of
ramdisk_flush::buf isn't used.

This is too useful a warning to disable, despite the occasional false
positive of this form.  The conventional approach is to suppress the
warning by explicitly initialising the variable to 0.

This has just come to light because 25275:27d63b9f111a reenabled
optimisation for this area of code, and gcc's data flow analysis
(which is required to trigger the uninitialised variable warning) only
occurs when optimisation is turned on.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/blktap2/drivers/block-remus.c

index 0af01f13e79cde1949f8bb2e24778a79727ce707..079588d820064c0cd244551192e97eddfd3a2181 100644 (file)
@@ -505,7 +505,7 @@ fail:
 static int ramdisk_flush(td_driver_t *driver, struct tdremus_state* s)
 {
        uint64_t* sectors;
-       char* buf;
+       char* buf = NULL;
        uint64_t base, batchlen;
        int i, j, count = 0;